// 输入框防抖指令
export const deinput = {
  mounted: function (el, binding) {
    let timer = null
    el.addEventListener('input', (e) => {
      clearTimeout(timer)
      timer = setTimeout(() => {
        binding.value(e.target.value)
      }, 500)
    })
  }
}
// 点击事件防抖指令
export const declick = {
  mounted: function (el, binding) {
    let timer = null
    el.addEventListener('click', (e) => {
      clearTimeout(timer)
      timer = setTimeout(() => {
        binding.value(e.target.value)
      }, 500)
    })
  }
}
let noImg = require('../assets/break.jpg')
// 图片懒加载
export const lazy = {
  mounted: function (el, binding) {
    el.src = noImg
    let io = new IntersectionObserver((entires) => {
      entires.forEach(item => {
              // 原图片元素
              let oImg = item.target
              if (item.intersectionRatio > 0 && item.intersectionRatio <= 1) {
                  oImg.setAttribute('src', binding.value)
                  io.unobserve(oImg) 
              } 
          })
     })
    io.observe(el) 
  }
}